package com.xm.proxy;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class DogInterceptor implements MethodInterceptor {
    @Override
    public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
        System.out.println("cglib 通过继承目标类并生成子类实现动态代理（无需目标实现接口无反射） method = " + method.getName());

        //前置增强处理
        MyUtil.before();
        Object res = proxy.invokeSuper(obj, args);
        //后置增强处理
        MyUtil.after();
        return res;
    }
}
